<?php defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

/* JoomLeague League Management and Prediction Game for Joomla!
 * @version $Id: show_tip_ranking.tpl.php 1151 2008-06-24 15:07:32Z julienv $
 * @package Joomleague
 * @copyright Copyright (C) 2007  JoomLeague
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see _joomleague_license.txt
 *  
 * Homepage: http://www.joomleague.de
 * Support: htt://www.joomleague.de/forum/
 * 
 * This file is part of JoomLeague.
 *  
 * JoomLeague is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * Please note that the GPL states that any headers in files and
 * Copyright notices as well as credits in headers, source files
 * and output (screens, prints, etc.) can not be removed.
 * You can extend them with your own credits, though...
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * The "GNU General Public License" (GPL) is available at
 * http://www.gnu.org/copyleft/gpl.html.
*/ 

?>
<div id="joomleague">
<!-- Header with Project Name-->
<?php if ($showTipRanking_config['show_project_heading'] == "1" OR $overall_config['show_project_heading'] == "1") { ?>
<div class="componentheading"<?php
if ($showTipRanking_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") echo ' style="float:left;"';?>><?php
echo $htmlHelper->showTitle($joomleague, $overall_config['project_heading_type']); ?></div>
<!-- Druckfunktion -->
<?php if ($showTipRanking_config['show_print_button'] == "1" OR $overall_config['show_print_button'] == "1") {
$htmlHelper->PrintIcon( $row, $params, false, '' );
};?>
<!-- Druckfunktion Ende -->
<?php } ?>
<!-- Header END -->

<!-- Bereichs�berschrift z.B Tabelle, Tippabgabe usw. -->
<table width="100%" class="contentpaneopen">
	<tr>
		<td class="contentheading">
		 <?php if($mode == 'all') printf ("%s",_JL_TIP_RANKING_ALL);
      else printf ("%s %s. %s&nbsp;&nbsp;&nbsp;",_JL_TIP_RANKING_DAY, $current_round, _JL_TIP_RANKING_MATCHDAY);?></td>
    <?php if ($showTipRanking_config['show_matchday_dropdown'] == "1") { ; if ($mode<>'all') {?>
    <td align="right" nowrap="nowrap"><?php echo _JL_MATCHDAYS_SELECT;?><?php echo $pageNav2 ?></td>
    <?php } else { ;?>
    </tr>
    <tr>
      <td align="left">
        <?php echo $htmlHelper->tiprankingnav($rounds, $from, $to, $showTipRanking_config, $table_config); ?>
      </td>
<?php  }
     } ?>
	</tr>
</table>
<br />
<!-- Bereichs�berschrift Ende -->

<!-- Inhalt -->

<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr class="sectiontableheader">
    <td align="left" class="sectiontableheader"><?php echo _JL_TIP_RANKING_RANG;?></td>
<?php if ($showTipRanking_config['show_user_icon'] == "1" && $showUser_config['show_image_from']>0){?>    
    <td align="center" class="sectiontableheader"><?php echo _JL_TIP_RANKING_AVATAR;?></td>
<?php } ;?>    
    <td align="left" class="sectiontableheader"><?php echo _USERNAME;?></td>
<?php 
if ($showTipRanking_config['show_tip_details'] == "1") echo '<td align="center" class="sectiontableheader">'._JL_TIP_RANKING_TIP_DETAILS.'</td>';
    echo '<td align="center" class="sectiontableheader">'._JL_TIP_RANKING_POINTS.'</td>';
if ($showTipRanking_config['show_avarage_points'] == "1") echo '<td align="center" class="sectiontableheader">&#216;</td>';
if ($showTipRanking_config['show_count_tips'] == "1") echo '<td align="center" class="sectiontableheader">'._JL_TIP_RANKING_COUNT_TIPS.'</td>';
if ($joomleague->tip_joker == "1" && $showTipRanking_config['show_count_joker'] == "1") echo '<td align="center" class="sectiontableheader">'._JL_TIPS_JOKER.'</td>';
if ($showTipRanking_config['show_count_topptips'] == "1") echo '<td align=" center" class="sectiontableheader">'._JL_TIP_RANKING_TOPPTIPS.'</td>';
if ($showTipRanking_config['show_count_difftips'] == "1") echo '<td align="center" class="sectiontableheader">'._JL_TIP_RANKING_DIFFTIPS.'</td>';
if ($showTipRanking_config['show_count_tendtipps'] == "1") echo '<td align="center" class="sectiontableheader">'._JL_TIP_RANKING_TENDTIPS.'</td>';
;?>
  </tr>
 
<?php
$k = 0;
  // new Gucky 2007/02/16 removed senseless queries and added assigned arrays $username, $results
  // changed picture_name to 'user_id' instead of 'username',
  // maybe also necessary for User in link to TipResults...
if($anzahltipper>0)
{
    $lastRank = 0;
foreach($showTipper as $val)
	{
    
	$class = ($k == 0)? 'sectiontableentry1' : 'sectiontableentry2';
	$tdclass = '';
	$bold = '';
    if ($val->user_id == $my->id) {
		$tdclass = 'highlight';
		$bold = 'font-weight:bold;';}  
	$format = "%s";
	
?>


  <tr class="<?php print $class;?>">
        <td class="<?php print $tdclass;?>" align="left"><?php if ($val->rank!=$lastRank) printf($format, $val->rank); ?></td>

<?php if ($showTipRanking_config['show_user_icon'] == "1" && $showUser_config['show_image_from']>0){?>
<?php
  $usericon = JL_TEMPLATE_FOLDERS_URL.'/images/unknown.gif';
  if ($showUser_config['show_image_from']==1) {
      $database->setQuery(sprintf("SELECT picture FROM #__joomleague_tip_members WHERE user_id = %s", $val->user_id));
      $jl_user_picture = $database->loadResult();
      if (!empty ($jl_user_picture))
        $usericon = _JOOMLA_JL_LIVE_SITE.'/images/joomleague/users/tn_'.$jl_user_picture;
  }
  if ($showUser_config['show_image_from']==2) {
      $database->setQuery(sprintf("SELECT avatar FROM #__comprofiler WHERE user_id = %s", $val->user_id));
      $cb_user_picture = $database->loadResult(); 
      if (!empty ($cb_user_picture))
        $usericon = _JOOMLA_JL_LIVE_SITE.'/images/comprofiler/tn'.$cb_user_picture;
  } 
  if ($showUser_config['show_image_from']==3) {
      $database->setQuery(sprintf("SELECT avatar FROM #__fb_users WHERE userid = %s", $val->user_id));
      $fb_user_picture = $database->loadResult();  
      if (!empty ($fb_user_picture))      
        $usericon = _JOOMLA_JL_LIVE_SITE.'/components/com_fireboard/avatars/'.$fb_user_picture;
      }
?>  
    <td align="center"><img src="<?php echo $usericon;?>" height="20px" alt="<?php echo $val->username; ?>" title="<?php echo $val->username;?>"/></td>
<?php } ;?>
    <td align="left" style="<?php print $bold;?>" >
    <?php if ($showTipRanking_config['link_name_to'] == "1")
    echo '<a href="'.sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showUser&amp;p='.$joomleague->id.'&amp;uid='.$val->user_id.JL_ITEMID_SUFFIX).'">'.$val->username.'</a>';
    else echo $val->username;
    echo '</td>';?>
    <?php if ($showTipRanking_config['show_tip_details'] == "1") { ;?><td align="center"><?php echo '<a href="'
         .sefRelToAbs(JL_COMPONENT_LINK.'&amp;func=showTipResults&amp;p='.$joomleague->id.'&amp;r='.$current_round.'&amp;uid='.$val->user_id
         .JL_ITEMID_SUFFIX).'">
    <img src="'._JOOMLA_JL_LIVE_SITE.'/components/com_joomleague/frontend/'.$joomleague->template.'/images/details.gif" border="none" alt="Tipps von '.$val->username.'" title="Tipps von '.$val->username.'"/></a>&nbsp;</td>';?><?php } ;?>
    <td align="center"><b><?php printf($format, intval($val->points))?></b></td>
   	<?php if ($val->tippCount>0) $averagepoints=number_format(round($val->points/$val->tippCount,2),2); else $averagepoints=number_format(0,2);?>
    <?php if ($showTipRanking_config['show_avarage_points'] == "1") { ;?><td align="center"><b><?php echo $averagepoints;?></b></td><?php } ;?>
    <?php if ($showTipRanking_config['show_count_tips'] == "1") { ;?><td align="center"><b><?php printf($format, $val->tippCount)?></b></td><?php } ;?>
    <?php if ($joomleague->tip_joker == "1" && $showTipRanking_config['show_count_joker'] == "1") {
              $query = sprintf("SELECT COUNT(joker) FROM #__joomleague_tip_results WHERE joker=1 AND project_id=%s AND user_id=%s", $joomleague->id, $val->user_id);
              $database->setQuery($query);
              $joker_count = $database->loadResult();?>
              <td align="center"><?php 
              if ($mode == "all") { 
              echo "<b>".$joker_count."</b>"; 
                if ($joomleague->tip_joker_limit > 0) echo "<b>/$joomleague->tip_joker_limit</b>";
                }
              else $query = sprintf("SELECT id FROM #__joomleague_rounds WHERE matchcode = %s AND project_id = %s", $current_round, $joomleague->id );
              $database->setQuery($query);
              $round_id = $database->loadResult();
              $query = sprintf("SELECT match_id FROM #__joomleague_matches WHERE round_id = %s AND project_id = %s", $round_id, $joomleague->id );
              $database->setQuery($query);
              $match_id = $database->loadResultArray();
              $match_id_list = implode(",",$match_id);
              $query = sprintf("SELECT COUNT(joker) FROM #__joomleague_tip_results WHERE project_id = %s AND user_id = %s AND match_id IN (%s)", $joomleague->id, $val->user_id, $match_id_list );
              $database->setQuery($query);
              $joker_count_matchday = $database->loadResult();
              if ($joker_count_matchday == "1") echo "*";?></td><?php } ;?>
    <?php if ($showTipRanking_config['show_count_topptips'] == "1") { ;?><td align="center"><b><?php printf($format, intval($val->hitsCount))?></b></td><?php } ;?>              
    <?php if ($showTipRanking_config['show_count_difftips'] == "1") { ;?><td align="center"><b><?php printf($format, intval($val->diffCount))?></b></td><?php } ;?>   
    <?php if ($showTipRanking_config['show_count_tendtipps'] == "1") { ;?><td align="center"><b><?php printf($format, intval($val->tendCount))?></b></td><?php } ;?>         
  </tr>
<?php
      $k = 1 - $k;
      $lastRank=$val->rank;
    }
  }
  else echo '</table><table align="center"><tr><td>'._JL_TIP_RESULTS_NO_TIP1.'</td></tr></table><table><tr><td></td></tr>';
?>
</table>
<div style="text-align:center">
<?php
$url=JL_COMPONENT_LINK.'&amp;func=showTipRanking&amp;p='.$joomleague->id.'&amp;mode='.$mode.'&amp;r='.($round);
if($page>0) echo '<a href="'.sefRelToAbs($url.'&amp;page='.($page-1).JL_ITEMID_SUFFIX).'">'._PN_PREVIOUS.'</a>&nbsp;&nbsp;';
//echo _PN_PAGE.':';
if ($anzahltipper>$limit) 
for ($x=0;$x<($anzahltipper/$limit);$x++) {
	$pagenumber=$x+1;
	if ($x!=$page) echo '<a href="'.sefRelToAbs($url.'&amp;page='.($x).'&amp;Itemid='.$Itemid).'">'.$pagenumber.'</a>&nbsp;';
	else echo '<b>'.$pagenumber.'</b>&nbsp;';
}
if($page+1<($anzahltipper/$limit)) echo '&nbsp;&nbsp;<a href="'.sefRelToAbs($url.'&amp;page='.($page+1).'&amp;Itemid='.$Itemid).'">'._PN_NEXT.'</a>';
?>
</div>
<?php
if ($showTipRanking_config['show_matchday_pagenav'] == "1") { ;?>

<!-- Matchdays Output  -->
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
   <td align="center">
   <br />
   <?php echo $pageNav ?></td>
  </tr>
</table>
<!-- Matchdays Output END -->
<?php } ;?>

<?php if ($showTipRanking_config['show_link_to_overall_ranking'] == "1") { ;?>
<table width="100%" align="center">
<tr>  
  <td align="center">
  <?php if ($mode == 1) {
  echo '<br />';
  echo "<a href=\"".sefRelToAbs(JL_COMPONENT_LINK."&amp;func=showTipRanking&amp;mode=all&amp;p=$joomleague->id".JL_ITEMID_SUFFIX)."\">";
  echo _JL_TIP_RANKING_ALL;
  echo "</a>";
  };?>
  </td>
</tr>
</table>
<?php } ;?>

<?php if ($showTipRanking_config['show_help'] == "1") { ;?>
<br />
<table width="96%" align="center" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <td valign="top"><b><?php echo _JL_HINT;?></b></td>
    <td><?php echo _JL_TIP_RANKING_HINT1;?><br /></td>
  </tr>
</table>
<?php } ;?>

<!-- Print Button START -->
<?php if ($showTipRanking_config['show_back_button'] > 0 OR $overall_config['show_back_button'] > 0) {;?>
<?php if ($showTipRanking_config['show_back_button'] == "1" OR $overall_config['show_back_button'] == "1") echo '<div align="left">'; else echo '<div align="right">';?>
<?php
$params = & new mosParameters( '' );
$params->def( 'back_button', true );
$params->def( 'popup', false );
mosHTML::BackButton( $params );
  echo "</div>";
};?>
<!-- Print Button END -->
</div>
